package com.hyk.controller;

import com.hyk.domain.SysMenu;
import com.hyk.dto.R;
import com.hyk.model.RolePrivilegesParam;
import com.hyk.service.SysRolePrivilegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "角色权限配置")
public class SysRolePrivilegeController {

    @Resource
    private SysRolePrivilegeService sysRolePrivilegeService;

    //查询角色权限配置列表
    @GetMapping("/roles_privileges")
    @ApiOperation("查询角色权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "角色的id")
    })
    public R<List<SysMenu>> findSysMenuAndPrivileges(Long roleId){
        List<SysMenu> sysMenus =
                sysRolePrivilegeService.findSysMenu(roleId);
        return R.ok(sysMenus);
    }

    //授予角色权限
    @PostMapping("/grant_privileges")
    @ApiOperation("授予角色权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "privilegeIds",value = "权限id集合"),
            @ApiImplicitParam(name = "roleId",value = "角色id")
    })
    public R grant(@RequestBody RolePrivilegesParam rolePrivilegesParam){
        sysRolePrivilegeService.grantPrivileges(rolePrivilegesParam);
        return R.ok();
    }

}
